from fastapi import APIRouter, Query,UploadFile
from tortoise.expressions import Q
from app.controllers.marketing.deposit import deposit_controller
from app.models import CustomerUser
from app.schemas.base import Success, SuccessExtra,Fail
from app.core.dependency import DependCustomerAuth
from app.core.ctx import CTX_USER_ID


mini_deposit_router = APIRouter()
model_name = "储值"


@mini_deposit_router.get("/list", summary=f"查看{model_name}列表", dependencies=[DependCustomerAuth])
async def get_list(
        page: int = Query(1, description="页码"),
        page_size: int = Query(10, description="每页数量"),
        direction: int = Query(1, description="1增加2减少"),
):
    user_id = CTX_USER_ID.get()
    q = Q()
    if user_id > 0:
        q &= Q(user_id=user_id)
    if direction>0:
        q &= Q(direction=direction)
    total, data = await deposit_controller.do_list(page=page, page_size=page_size, search=q)

    for item in data:
        if item['direction'] == 1:
            item['direction_name'] = "增加"
        else:
            item['direction_name'] = "减少"

    return SuccessExtra(data=data, total=total, page=page, page_size=page_size)
